package com.bilibili.lzx.service;

import com.bilibili.lzx.dao.FollowingGroupDao;
import com.bilibili.lzx.dao.UserFollowingDao;
import com.bilibili.lzx.dao.domain.FollowingGroup;
import com.bilibili.lzx.dao.domain.UserFollowing;
import com.bilibili.lzx.dao.domain.constant.UserConstant;
import com.bilibili.lzx.dao.domain.exception.ConditionException;
import com.mysql.cj.util.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author lzx
 * @date 2024/8/20 20:58
 */
@Service
public class FollowingGroupService {


    @Resource
    private FollowingGroupDao followingGroupDao;

    public  FollowingGroup getById(Long groupId) {
        return followingGroupDao.getById(groupId);
    }



    public FollowingGroup getByType(String type) {
        return followingGroupDao.getByType(type);
    }

    public List<FollowingGroup> getByUserId(Long userId) {
        return followingGroupDao.getByUserId(userId);
    }

    public List<FollowingGroup> getUserFollowingGroups(Long userId){
        return followingGroupDao.getUserFollowingGroups(userId);
    }

    public Long addUserFollowingGroup(FollowingGroup followingGroup) {
        if(StringUtils.isNullOrEmpty(followingGroup.getName())){
            throw new ConditionException("分组名不能为空");
        }
        followingGroup.setCreateTime(new Date());
        followingGroup.setType(UserConstant.USER_FOLLOWING_GROUP_TYPE_USER);
        followingGroupDao.addUserFollowingGroup(followingGroup);
        return followingGroup.getId();
    }
}
